from django.db.models import Q
from django.shortcuts import render, redirect
from django.urls import reverse

from movie.models import MovieInfo
from movie.views import single

# Create your views here.
def search(request):

    try:
        datalist=MovieInfo.objects.filter(movie_name__icontains=request.POST['Search'])
    except Exception:
        try:
            datalist=MovieInfo.objects.filter(movie_name__icontains=request.POST['email'])
        except Exception:
            return_url = request.environ.get('HTTP_REFERER', reverse('index'))
            return redirect(return_url)

    if datalist:
        pk=datalist[0].pk
        return single(request,pk)
    else:
        return_url = request.environ.get('HTTP_REFERER', reverse('index'))
        return redirect(return_url)


